﻿using DDD.Simple.DomainBase;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace Product.Domain.Core
{
    public class ProductSPU
        : IAggregationRoot
    {
        public ProductSPU()
        {
            ProductSKUs = new HashSet<ProductSKU>();
        }
        [Key]
        public Guid Id { get; set; }
        [Required(ErrorMessage = "商品编码不能为空"), MaxLength(500, ErrorMessage = "商品编码长度过长")]
        public string Code { get; set; }
        public string ProductSPUName { get; set; }
        public string ProductSPUDesc { get; set; }
        public virtual ICollection<ProductSKU> ProductSKUs { get; set; }

        public ProductSPU(Guid id,string name,string desc,List<ProductSKU> skus)
            :this()
        {
            Id = id;
            Code = $"Code{id}";
            ProductSPUName = name;
            ProductSPUDesc = desc;

            foreach (var sku in skus)
            {
                ProductSKUs.Add(sku);
            }
        }
    }
}

